'use strict';
var jwt = require('jsonwebtoken');
const Controller = require('egg').Controller;

const data = {
  '00001000': {
    name: '厚底鼓釜靓味陶瓷煲',
    price: '99',
    rate: '100%',
    reason: [
      '鼓釜设计，蒸汽环流更充分',
      '进口锂辉石，480度骤温差',
      '下沉锅盖，三联排汽 有效防止外溢'
    ],
    image: [
      'https://yanxuan-item.nosdn.127.net/388ae501ea916a052cc54016c2607a92.png?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/069d6679fae29e9e3e6bae28f1350e28.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/85aed7f976cf291d2b5c733a304c01a8.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/929608fd40419d15b86f209f2f6dfe70.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
    ]
  },
  '00001001': {
    name: '鲜虾活冻，原箱进口厄瓜多尔白虾 1.4kg',
    price: '129',
    rate: '94.4%',
    reason: [
      '厄瓜多尔沿岸深海捕捞，鲜虾活冻，保留新鲜味道',
      '适合多种烹饪方法，简单易制',
      '每只虾都经过人工细心挑选，个大饱满'
    ],
    image: [
      'https://yanxuan-item.nosdn.127.net/e534135018967adc349e514e32cf26fd.png?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/74dd509c10e08bc10cc263830368eedf.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/e8fd5d33b3179900a3e765c40ca57177.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/2c371b38c0400ea8bdbf3ad005da6d1c.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
    ]
  },
  '00001002': {
    name: '冰封住的绵密香甜，泰国金枕榴莲冻肉 300克',
    price: '68',
    rate: '98.4%',
    reason: [
      '泰国当地剥肉速冻，留存新鲜滋味',
      '真空锁鲜，开盒即食，榴莲控随时畅食',
      '肉多核小，甜糯微苦，榴莲入门之选'
    ],
    image: [
      'https://yanxuan-item.nosdn.127.net/5b8a31f4fa0045defafbd54c60f7346c.png?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/dc2d7d5ea2edd815428e64a7705b484d.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/d421db66d7dd061ededcc2bc430780e4.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/58ca47620ca57d2deb4d5293350c7f9b.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
    ]
  },
  '00001003': {
    name: '澳洲红酒先锋，奔富Bin407 750毫升',
    price: '728',
    rate: '96.0%',
    reason: [
      '澳大利亚红酒的象征，奔富酒庄出品',
      '百年酒庄源自1844，传承经典风味',
      '原瓶进口，瓶身防伪编码，品质保证'
    ],
    image: [
      'https://yanxuan-item.nosdn.127.net/04b30b614cddd39e612e3e67857c1e93.png?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/5d60642ab1b400a0ceed6a3d6ce6cce3.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/a8b718b81de32fc9b07fa22e9dd26b1b.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/65fdab400d25e330b5ee4f26fffd24a3.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
    ]
  },
  '00001004': {
    name: '鸿运刀 暖奢鸡翅木刀具系列',
    price: '129',
    rate: '99.2%',
    reason: [
      '德国进口高锰钢，集高硬度与不易崩口性能于一体',
      '40度45分钻石角度双向开刃，顺滑切割，锋利持久',
      '手柄采用红木系中的鸡翅木，温润手感，冬天使用不冻手'
    ],
    image: [
      'https://yanxuan-item.nosdn.127.net/67e5a14b1fd586503791a28f4d5d4f65.png?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/af16804173a35b71a35134e49dc1d1f3.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/db819d939bbf59f04b2c011be8b4f3b7.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
      'https://yanxuan-item.nosdn.127.net/63e66e2da9383020446c969b9be5afc4.jpg?type=webp&imageView&quality=75&thumbnail=750x0',
    ]
  },
}

class AppController extends Controller {
  async newBanner() {
    this.ctx.body =
    {
      code: 1,
      msg: 'ok',
      data: [
        {
          id: '00000010',
          image: 'https://yanxuan.nosdn.127.net/2d30b31b6b6edd74471eb39bd920c2b9.jpg'
        },
        {
          id: '00000011',
          image: 'https://yanxuan.nosdn.127.net/372affa9488387b628434e533b8b644c.jpg'
        },
        {
          id: '00000012',
          image: 'https://yanxuan.nosdn.127.net/879b14f8e4f4795444bc872047b333d2.jpg'
        }]
    }
  }

  async banner() {
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: [
        {
          id: '00000006',
          image: 'https://yanxuan.nosdn.127.net/8fc74aa52814aed3f2936459f9278350.png?type=webp&imageView&quality=75&thumbnail=750x0'
        },
        {
          id: '00000003',
          image: 'https://yanxuan.nosdn.127.net/baae1ad9b0e32643e9196eebfa503f9a.jpg?type=webp&imageView&quality=75&thumbnail=750x0'
        },
        {
          id: '00000008',
          image: 'https://yanxuan.nosdn.127.net/fdf3b4f042eb98dbc7a1a38d22641c67.jpg?type=webp&imageView&quality=75&thumbnail=750x0'
        },
        {
          id: '00000009',
          image: 'https://yanxuan.nosdn.127.net/5dd18d340a082b59530fe6dd6e131d44.jpg?type=webp&imageView&quality=75&thumbnail=750x0'
        }]
    }
  }

  async getMainMenu() {
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: [
        {
          id: '00000001',
          title: '新品首发',
          image: 'https://yanxuan.nosdn.127.net/c6fd8835a6400b7da7a016ad85506b69.png'
        },
        {
          id: '00000002',
          title: '居家生活',
          image: 'https://yanxuan.nosdn.127.net/fede8b110c502ec5799702d5ec824792.png'
        },
        {
          id: '00000003',
          title: '服饰鞋包',
          image: 'https://yanxuan.nosdn.127.net/896a3beac514ae8f40aafe028e5fec56.png'
        },
        {
          id: '00000004',
          title: '美食酒水',
          image: 'https://yanxuan.nosdn.127.net/37520d1204a0c55474021b43dac2a69e.png'
        },
        {
          id: '00000005',
          title: '母婴亲子',
          image: 'https://yanxuan.nosdn.127.net/559d2a240ec20b096590a902217009ff.png'
        },
        {
          id: '00000006',
          title: '运动旅行',
          image: 'https://yanxuan.nosdn.127.net/5c088559ebcc3f0ffcda663f04dfbeb2.png'
        },
        {
          id: '00000007',
          title: '数码家电',
          image: 'https://yanxuan.nosdn.127.net/fbca8e1f2948f0c09fc7672c2c125384.png'
        },
        {
          id: '00000008',
          title: '全球特色',
          image: 'https://yanxuan.nosdn.127.net/f7281169d4e82d5d8d52aa1fec83fe01.png'
        }]
    }
  }

  async getGuessLikeList() {
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: [
        {
          id: '00001000',
          image: 'https://yanxuan-item.nosdn.127.net/579c0fad57cdaaece61c61d20ac10c4b.png?type=webp&imageView&quality=65&thumbnail=330x330',
          name: '厚底鼓釜靓味陶瓷煲',
          description: '鼓釜设计，蒸汽环流更充分',
          price: 99
        },
        {
          id: '00001001',
          image: 'https://yanxuan-item.nosdn.127.net/6287d92cd756b0ab8e47631d891996be.png?type=webp&imageView&quality=65&thumbnail=330x330',
          name: '鲜虾活冻，原箱进口厄瓜多尔白虾 1.4kg',
          description: '新鲜优质虾品，轻松拥有星级享受',
          price: 129
        },
        {
          id: '00001002',
          image: 'https://yanxuan-item.nosdn.127.net/5b8a31f4fa0045defafbd54c60f7346c.png?type=webp&imageView&quality=65&thumbnail=330x330',
          name: '冰封住的绵密香甜，泰国金枕榴莲冻肉 300克',
          description: '泰国进口，绵密香醇',
          price: 68
        },
        {
          id: '00001003',
          image: 'https://yanxuan-item.nosdn.127.net/787af3d01eb11d2c8ffddca53d6243f6.png?type=webp&imageView&quality=65&thumbnail=330x330',
          name: '澳洲红酒先锋，奔富Bin407 750毫升',
          description: '澳洲酒业巨头出品',
          price: 728
        },
        {
          id: '00001004',
          image: 'https://yanxuan-item.nosdn.127.net/faf82adb59b048d745a0bc8e4a5d45b1.png?type=webp&imageView&quality=65&thumbnail=330x330',
          name: '鸿运刀 暖奢鸡翅木刀具系列',
          description: '德国进口钢材持久锋利，暖奢鸡翅红木温润双手',
          price: 129
        },
      ]
    }
  }

  async getNewGoodsList() {
    this.ctx.body =
    {
      code: 1,
      msg: 'ok',
      data: [{
        id: '00001005',
        image: 'https://yanxuan-item.nosdn.127.net/033aca51607876112883541926cfd1e1.png?type=webp&imageView&quality=65&thumbnail=330x330',
        name: '怎么睡都舒适 泰国93%天然乳胶床垫5cm7.5cm',
        price: 1250
      }, {
        id: '00001006',
        image: 'https://yanxuan-item.nosdn.127.net/e728c09d17828a7aa666b7b8eb7de5fe.png?type=webp&imageView&quality=65&thumbnail=330x330',
        name: '琉璃橘光水润镜面唇釉',
        price: 49.9
      }, {
        id: '00001007',
        image: 'https://yanxuan-item.nosdn.127.net/67fe13d658fa9f8ce98bd45cc601a316.png?type=webp&imageView&quality=65&thumbnail=330x330',
        name: '新西兰3.6g蛋白纯牛奶250ml*48盒 再赠6盒',
        price: 145
      }, {
        id: '00001008',
        image: 'https://yanxuan-item.nosdn.127.net/554ee16fa5e9b3a56ad8cf7d3766e4af.png?type=webp&imageView&quality=65&thumbnail=330x330',
        name: '夏日桌面清凉伴侣，超静音桌面小风扇',
        price: 52
      }]
    }
  }

  async getProductDetail() {
    const { id } = this.ctx.query;
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: data[id]
    }
  }

  async getCart() {
    const token = this.ctx.cookies.get("token", {
      signed: false,
      encrypt: true
    });
    const decoded = jwt.verify(token, "aaa");
    const res = await this.ctx.model.Cart.find({ userId: decoded.id })
    let totalPrice = 0
    res.map((item) => {
      totalPrice += item.price * item.num
    })
    this.ctx.body = {
      code: 0,
      msg: 'ok',
      data: {
        cartList: res,
        totalPrice
      }
    };
  }

  async addCart() {
    const token = this.ctx.cookies.get("token", {
      signed: false,
      encrypt: true
    });
    const decoded = jwt.verify(token, "aaa");
    const { id } = this.ctx.request.body;
    const res = await this.ctx.model.Cart.findOne({ id: id, userId: decoded.id });
    if (res) {
      const re = await this.ctx.model.Cart.updateOne(
        { id: id, userId: decoded.id },
        { num: res.num + 1 }
      );
      this.ctx.body = {
        code: 1,
        msg: 'ok',
      };
    } else {
      const item = data[id];
      if (item) {
        console.log(']]]', decoded.id)
        await this.ctx.model.Cart.create({
          id,
          name: item.name,
          image: item.image[0],
          price: item.price,
          num: 1,
          userId: decoded.id
        })
        this.ctx.body = {
          code: 1,
          msg: 'ok',
        };
      } else {
        this.ctx.body = {
          code: -1,
          msg: 'error',
        };
      }
    }
  }

  // 删除购物车
  async deleteCart() {
    const { id } = this.ctx.request.body;
    const token = this.ctx.cookies.get("token", {
      signed: false,
      encrypt: true
    });
    const decoded = jwt.verify(token, "aaa");
    const res = await this.ctx.model.Cart.remove({
      id,
      userId: decoded.id
    });
    this.ctx.body = {
      code: 1,
      msg: 'ok',
    };
  }


  async getCartNum() {
    const token = this.ctx.cookies.get("token", {
      signed: false,
      encrypt: true
    });
    const decoded = jwt.verify(token, "aaa");
    const res = await this.ctx.model.Cart.find({ userId: decoded.id }, { num: 1, _id: 0 });
    let count = 0
    res.map((item) => {
      count += item.num
    })
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: count
    };
  }

  async changeNum() {
    const token = this.ctx.cookies.get("token", {
      signed: false,
      encrypt: true
    });
    const decoded = jwt.verify(token, "aaa");
    const { id, num } = this.ctx.request.body;
    const res = await this.ctx.model.Cart.findOne({ id: id, userId: decoded.id });
    if (res) {
      const re = await this.ctx.model.Cart.updateOne(
        { id: id, userId: decoded.id },
        { num: num },
      );
      const allRes = await this.ctx.model.Cart.find({ userId: decoded.id })
      let totalPrice = 0
      allRes.map((item) => {
        totalPrice += item.price * item.num
      })
      this.ctx.body = {
        code: 1,
        msg: 'ok',
        data: totalPrice
      };
    } else {
      this.ctx.body = {
        code: -1,
        msg: 'error'
      };
    }
  }

  // 添加订单
  async getOrder() {
    this.ctx.body =
    {
      code: 0,
      msg: 'ok',
      data: [
        {
          orderId: '29074478',
          orderList:
            [{
              id: '00001000',
              image: 'https://yanxuan-item.nosdn.127.net/579c0fad57cdaaece61c61d20ac10c4b.png?type=webp&imageView&quality=65&thumbnail=330x330',
              name: '厚底鼓釜靓味陶瓷煲',
              price: 99,
              num: 1
            }, {
              id: '00001003',
              image: 'https://yanxuan-item.nosdn.127.net/787af3d01eb11d2c8ffddca53d6243f6.png?type=webp&imageView&quality=65&thumbnail=330x330',
              name: '澳洲红酒先锋，奔富Bin407 750毫升',
              price: 728,
              num: 1
            }]
        },
        {
          orderId: '29074477',
          orderList: [{
            id: '00001001',
            image: 'https://yanxuan-item.nosdn.127.net/6287d92cd756b0ab8e47631d891996be.png?type=webp&imageView&quality=65&thumbnail=330x330',
            name: '鲜虾活冻，原箱进口厄瓜多尔白虾 1.4kg',
            price: 129,
            num: 1
          }]
        },
        {
          orderId: '29074476',
          orderList:
            [{
              id: '00001004',
              image: 'https://yanxuan-item.nosdn.127.net/faf82adb59b048d745a0bc8e4a5d45b1.png?type=webp&imageView&quality=65&thumbnail=330x330',
              name: '鸿运刀 暖奢鸡翅木刀具系列',
              price: 129,
              num: 2
            }, {
              id: '00001002',
              image: 'https://yanxuan-item.nosdn.127.net/5b8a31f4fa0045defafbd54c60f7346c.png?type=webp&imageView&quality=65&thumbnail=330x330',
              name: '冰封住的绵密香甜，泰国金枕榴莲冻肉 300克',
              price: 68,
              num: 3
            }, {
              id: '00001000',
              image: 'https://yanxuan-item.nosdn.127.net/579c0fad57cdaaece61c61d20ac10c4b.png?type=webp&imageView&quality=65&thumbnail=330x330',
              name: '厚底鼓釜靓味陶瓷煲',
              price: 99,
              num: 1
            }]
        },
      ]
    };
  }

  async getTopic() {
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: [{
        image: 'https://yanxuan.nosdn.127.net/5f7a095a21aea36bb10ae02f5528c12c.jpg?imageView&thumbnail=345y179.2207792207792&quality=95',
        title: '宅家防疫必买好物，提高免疫力、清洁灭病菌，打响健康战"役"！',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '1217K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/b9c2b0632d9380e8a0bfaa089b9df615.jpg?imageView&thumbnail=345y345&quality=95',
        title: '印花家居、巧克力礼盒、便携消毒等2月必买好物，陪你进入早春',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '83K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/cf7d6d25c51e29cd1da35282ff42bb7f.jpg?imageView&thumbnail=345y191.66666666666669&quality=95',
        title: '全方位清扫神器，教你轻轻松松让全屋都整洁',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '119K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/2851e087a739e19aa72593c6fb271623.jpg?imageView&thumbnail=345y191.66666666666669&quality=95',
        title: '宅在家里怎么做防护？加强锻炼勤消毒~',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '153'
      }, {
        image: 'https://yanxuan.nosdn.127.net/3da09277de315c67d6478774fa87c634.jpg?imageView&thumbnail=345y345&quality=95',
        title: '杯测评分85.5的精品咖啡，懂行的进！',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '16K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/db58391bde7ba64b5b9e8bec4087c856.jpg?imageView&thumbnail=345y345&quality=95',
        title: '味蕾被照顾好了，心里才有踏实感',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '126K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/f0d8e9d0920686bd6afbdaa1679bb3f3.jpg?imageView&thumbnail=345y345&quality=95',
        title: '为什么我总在夜里吃火腿猪肉罐头',
        avatar: 'http://yanxuan.nosdn.127.net/d4379373d8e5200bdd8430896a6a5fbf.jpg?imageView&quality=65&thumbnail=48y48',
        name: '网易味央：小周',
        num: '106K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/19169ad26f2ebea39a0a92c6e1be9a54.jpg?imageView&thumbnail=345y345&quality=95',
        title: '被日本人称赞不已的零食，你吃了也会喜欢',
        avatar: 'http://yanxuan.nosdn.127.net/d11ad04118ebd99e53cb2779a1caa872.png?imageView&quality=65&thumbnail=48y48',
        name: '网易员工精选',
        num: '64K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/6c4a1827bb4157c37dfd31c9df63d0dd.jpg?imageView&thumbnail=345y191.66666666666669&quality=95',
        title: '与其依赖医生朋友，不如马上get这些家庭护理技能！医护用品9.9元起>',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '156K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/f03736e70800d461b61d34fd55cb94d5.jpg?imageView&thumbnail=345y345&quality=95',
        title: '吃货心中，总有一块地是留给火锅的',
        avatar: 'http://yanxuan.nosdn.127.net/d11ad04118ebd99e53cb2779a1caa872.png?imageView&quality=65&thumbnail=48y48',
        name: '网易员工精选',
        num: '97K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/12ff3c831f031c9170bd6d88a4732720.jpg?imageView&thumbnail=345y345&quality=95',
        title: '圣诞节，怎么花小钱送个高逼格的礼物？',
        avatar: 'http://yanxuan.nosdn.127.net/99b419280b28b4c19e25000f7e8b5174.jpg?imageView&quality=65&thumbnail=48y48',
        name: '网易游戏：柠檬',
        num: '49K'
      }, {
        image: 'https://yanxuan.nosdn.127.net/8333e3d60057bc40c803bde6e3e8332e.jpg?imageView&thumbnail=345y345&quality=95',
        title: '64倍浓稠，加了枇杷叶的真·枇杷膏',
        avatar: 'http://yanxuan.nosdn.127.net/d11ad04118ebd99e53cb2779a1caa872.png?imageView&quality=65&thumbnail=48y48',
        name: '网易员工精选',
        num: '79K'
      }, {
        image: 'http://yanxuan.nosdn.127.net/b099199614286bf782928b83094c94a0.jpg?imageView&thumbnail=345y191.66666666666669&quality=95',
        title: '严选卖爆的无限回购美食清单！严选一整个办公室都在吃！',
        avatar: 'http://yanxuan.nosdn.127.net/d0929d6affc4f1272da63f13fac44c53.jpg?imageView&quality=65&thumbnail=48y48',
        name: '选妹',
        num: '1381K'
      }]
    };
  }

  async getBanner() {
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: ['https://cdn.cnbj1.fds.api.mi-img.com/planet/abe5e0d6ab4883bb0ad1adde17b54808-1746009239665_%E7%A4%BE%E5%8C%BAbanner1860_930_compress.jpeg', 'https://cdn.cnbj1.fds.api.mi-img.com/planet/e2b66cbc35485c886d9815a0bec486ff-1746237032355_20250503-094918.jpeg']
    }
  }

  async getNewsList() {
    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data: [{
        avatar: 'https://cdn.cnbj1.fds.api.mi-img.com/middle.community.vip.bkt/6ce9b375aef9d6ed335c32f2ccc86637?thumb=1&w=100&h=100&quality=80',
        name: '花花无敌帅',
        content: '能不能把这个侧返这个小白条，搞成原生的侧返如图二，或者别的侧返',
        images: ['https://cdn.cnbj1.fds.api.mi-img.com/middle.community.vip.bkt/558eab9bc4f4f90ac513600c12a0594c?thumb=1&w=640&q=80&f=webp', 'https://cdn.cnbj1.fds.api.mi-img.com/middle.community.vip.bkt/2380f3cc6b4b4d408ddd8a3c21cbdf0e?thumb=1&w=640&q=80&f=webp'],
        date: '02:16'
      },
      {
        avatar: 'https://cdn.cnbj1.fds.api.mi-img.com/middle.community.vip.bkt/vip1567121342036?thumb=1&w=100&h=100&quality=80',
        name: '冷月飘风',
        content: '五一，阳光正好，这个假期没有选择出外旅游，而是与亲戚们相聚。饭桌上摆满了家乡的味道，欢声笑语回荡在房间。亲情是那根无形的线，无论我们走多远，都会被紧紧相连。珍惜那些一起度过的时光，是生活里最温暖的篇章。珍惜每一次相聚，让亲情在岁月中愈发醇厚。',
        images: ['https://cdn.cnbj1.fds.api.mi-img.com/middle.community.vip.bkt/4604abe38b645fc8ae4946a30c33cddf?thumb=1&w=320&q=80&f=webp', 'https://cdn.cnbj1.fds.api.mi-img.com/middle.community.vip.bkt/903775c7f08de8400493360286a8c458?thumb=1&w=320&q=80&f=webp', 'https://cdn.cnbj1.fds.api.mi-img.com/middle.community.vip.bkt/62ac31ab73d87f1cab90cdc4956f07f8?thumb=1&w=320&q=80&f=webp'],
        date: '05-06'
      }]
    }
  }

  async getMallList() {
    const { low, high } = this.ctx.query;
    let data = [{
      id: '1',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/5ed659adaedf3b33ed141930314e8bd1.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '1999',
      description: 'Turbo 4 Pro 好看，更能打',
      name: 'REDMI Turbo 4 Pro'
    }, {
      id: '2',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202502251811_93715df0882e43e252843e3c7b775570.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '6499',
      description: '莱卡1英寸主摄|莱卡2亿长焦',
      name: 'Xiaomi 15 Ultra'
    }, {
      id: '3',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/00eb27ead9512a7f12604ad3469460b6.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '1799',
      description: 'Turbo 4 Pro 好看又能打',
      name: 'REDMI Turbo 4'
    }, {
      id: '4',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202412271148_a4cb76ca76ad26ac81da44ad1a69ebd1.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '499',
      description: '【持久续航】5160mAh 大电池',
      name: 'REDMI 14C'
    }, {
      id: '5',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202411261127_8d9eefc4ea604b3c2c20ef4df1312591.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '3299',
      description: '骁龙8至尊版|2K新国屏|全焦段影像',
      name: 'REDMI K80 Pro'
    }, {
      id: '6',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202411261112_496adbd3fa76742689e9b8f5c4251efc.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '2499',
      description: '骁龙8至尊版|2K新国屏',
      name: 'REDMI K80'
    }, {
      id: '7',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/089128152bd814096a99249a487e383d.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '4199',
      description: '莱卡光学 Summilux 高速镜头',
      name: 'Xiaomi 15'
    }, {
      id: '8',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/5f4d5d4fa89236436e9d44e2b2e6ebac.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '4999',
      description: '莱卡光学 Summilux 高速镜头',
      name: 'Xiaomi 15 Pro'
    }]


    data = data.filter((item) => {
      // console.log(item[type], key)
      return ((!low && !high) || (Number(item.price) <= high && Number(item.price) >= low));
    })

    this.ctx.body = {
      code: 1,
      msg: 'ok',
      data
    }
  }

  async addCart1() {

    let data = [{
      id: '1',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/5ed659adaedf3b33ed141930314e8bd1.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '1999',
      description: 'Turbo 4 Pro 好看，更能打',
      name: 'REDMI Turbo 4 Pro'
    }, {
      id: '2',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202502251811_93715df0882e43e252843e3c7b775570.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '6499',
      description: '莱卡1英寸主摄|莱卡2亿长焦',
      name: 'Xiaomi 15 Ultra'
    }, {
      id: '3',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/00eb27ead9512a7f12604ad3469460b6.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '1799',
      description: 'Turbo 4 Pro 好看又能打',
      name: 'REDMI Turbo 4'
    }, {
      id: '4',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202412271148_a4cb76ca76ad26ac81da44ad1a69ebd1.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '499',
      description: '【持久续航】5160mAh 大电池',
      name: 'REDMI 14C'
    }, {
      id: '5',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202411261127_8d9eefc4ea604b3c2c20ef4df1312591.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '3299',
      description: '骁龙8至尊版|2K新国屏|全焦段影像',
      name: 'REDMI K80 Pro'
    }, {
      id: '6',
      image: '//cdn.cnbj1.fds.api.mi-img.com/nr-pub/202411261112_496adbd3fa76742689e9b8f5c4251efc.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '2499',
      description: '骁龙8至尊版|2K新国屏',
      name: 'REDMI K80'
    }, {
      id: '7',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/089128152bd814096a99249a487e383d.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '4199',
      description: '莱卡光学 Summilux 高速镜头',
      name: 'Xiaomi 15'
    }, {
      id: '8',
      image: '//cdn.cnbj1.fds.api.mi-img.com/mi-mall/5f4d5d4fa89236436e9d44e2b2e6ebac.png?thumb=1&w=400&h=400&f=webp&q=90',
      price: '4999',
      description: '莱卡光学 Summilux 高速镜头',
      name: 'Xiaomi 15 Pro'
    }]

    const token = this.ctx.cookies.get("token", {
      signed: false,
      encrypt: true
    });
    const decoded = jwt.verify(token, "aaa");
    const { id } = this.ctx.request.body;
    const res = await this.ctx.model.Cart.findOne({ id: id, userId: decoded.id });
    if (res) {
      const re = await this.ctx.model.Cart.updateOne(
        { id: id, userId: decoded.id },
        { num: res.num + 1 }
      );
      this.ctx.body = {
        code: 1,
        msg: 'ok',
      };
    } else {
      const item = data[id];
      if (item) {
        await this.ctx.model.Cart.create({
          id,
          name: item.name,
          image: item.image,
          price: item.price,
          num: 1,
          userId: decoded.id
        })
        this.ctx.body = {
          code: 1,
          msg: 'ok',
        };
      } else {
        this.ctx.body = {
          code: -1,
          msg: 'error',
        };
      }
    }
  }


}

module.exports = AppController;